﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using BakalarskaPraca.Generation.Data;
using BakalarskaPraca.Generation.Tasks;
using BakalarskaPraca.Generation.Tasks.Abstract;

namespace BakalarskaPraca.Forms.GenerationSettingsForms
{
    public partial class PlantSimulationDistributionSettingsForm : PlantSimulationDistributionSettingsFormBase
    {
        public PlantSimulationDistributionSettingsForm()
        {
            InitializeComponent();
        }

        public override bool ShowSettings(PlantSimulationPlantDistributionGeneration generationProcess)
        {
            this.PlantSeecCountNTB.IntValue = generationProcess.PlantSeedCount;
            this.PlantIterationsCountNTB.IntValue = generationProcess.SimulationIterationCount;
            this.textBox1.Text = generationProcess.PlantLibrarySource;
            if (this.ShowDialog() == DialogResult.OK)
            {
                generationProcess.PlantSeedCount = this.PlantSeecCountNTB.IntValue;
                generationProcess.SimulationIterationCount = this.PlantIterationsCountNTB.IntValue;
                generationProcess.PlantLibrarySource = this.textBox1.Text;
                return true;
            }
            return false;
        }

        public override GenerationProcess GetNewGenerationProcess(List<HumidityPolygon> polygons, ModelData modelData)
        {
            return new PlantSimulationPlantDistributionGeneration(polygons, modelData);
        }

       
        private void LibraryBrowseBtnClick(object sender, EventArgs e)
        {
            if (this.PlantLibraryOpeDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = this.PlantLibraryOpeDialog.FileName;
            }
        }

        private void PlantSimulationDistributionSettingsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK && !File.Exists(this.textBox1.Text))
            {
                MessageBox.Show("File '" + this.textBox1.Text + "' does not exist.");
                e.Cancel = true;
            }   
        }
    }

    public class PlantSimulationDistributionSettingsFormBase : GenerationSettingsFormBase<PlantSimulationPlantDistributionGeneration> {}
}
